package com.thb.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Repository;

@Component
public class SpringContextUtils implements ApplicationContextAware  {
	
	 	private static ApplicationContext context;
	
	    public void setApplicationContext(ApplicationContext contex) throws BeansException {
	        SpringContextUtils.context=contex;
	    }
	    
	    public static ApplicationContext getApplicationContext() {
            return context;
	    }
	 	
	    @SuppressWarnings("unchecked")
		public static <T> T getBean(String beanName){
	        try {
				return (T)context.getBean(beanName);
			} catch (BeansException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	        return null;
	    }
	    
	    public static <T> T getBean(Class<T> clazz){
	        return context.getBean(clazz);
	    }
	      
	   /* public static String getMessage(String key){
	        return context.getMessage(key, null, Locale.getDefault());
	    }*/

}
